package com.isoftstone.controller;
import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import com.isoftstone.pojo.Job;
import com.isoftstone.service.JobService;
@Controller
public class JobController {

	@Autowired
	private JobService jobService;
	
	@RequestMapping("/job")
	public String jump(Model model,String isstock) {
		List<Job> list=  jobService.selectother(isstock.equals("yes"));
		model.addAttribute("list", list);
		return "listjob";
	}
	@RequestMapping(path="/modifyjob",method=RequestMethod.POST)	
	public String inset(Model model,Job job) {
		java.util.Date dt = new java.util.Date();
		java.text.SimpleDateFormat sdf =new java.text.SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
		String currentTime = sdf.format(dt);
		job.setCreatetime(currentTime);
		jobService.register(job);
		List<Job> list=  jobService.selectother(false);
		model.addAttribute("list", list);
		return "listjob";
	}

	@RequestMapping("/updatejob.do")
	public String update(Model model,String id) {
		jobService.update(Integer.parseInt(id));
		List<Job> list=  jobService.selectother(true);
		model.addAttribute("list", list);
		return "listjob";
	}
	@RequestMapping("/deletejob.do")
	public String delete(Model model,String id) {
		Job job=jobService.select(Integer.parseInt(id));
		boolean flag=job.isIsstock();
		jobService.delete(Integer.parseInt(id));
		List<Job> list=  jobService.selectother(flag);
		model.addAttribute("list", list);
		return "listjob";
	}
	@RequestMapping("/addjob.do")
	public String register() {
		return "addjob";
	}
	@RequestMapping("/detailjob")
	public String detail(Model model, String id) {
		//int i=Integer.parseInt(id);
		Job job = jobService.select(Integer.parseInt(id));
		model.addAttribute("job", job);
		return "detailjob";
	}
}
